<?php

namespace App;
use Session;
use Illuminate\Database\Eloquent\Model;
use DB;
class Node extends Model{
    //权限展示  分页
    public function lists($node_title){
       return $info= DB::table('Node')->where('node_title','like','%'.$node_title.'%')->paginate(10);
    }

    //添加权限
    public function add($data){
        $info = [
            'node_name'=>$data['node_name'],
            'node_title'=>$data['node_title'],
            'status'=>$data['status'],
            'level'=>$data['level'],
            'pid'=>$data['pid'],
            'display'=>$data['display']
        ];
        return DB::table('node')->insert($info);

    }

    //删除权限 修改状态值
    public function del($node_id){
        return DB::table('node')->where('node_id',$node_id)->update(['status'=>0]);
    } 

    //查询一条
    public function fineOne($node_id){
        $oneList= DB::table('node')->where('node_id',$node_id)->first();
        $fulist= DB::table('node')->where('level',1)->get();
        $arr['oneList']=$oneList;
        $arr['fulist']=$fulist;
        return $arr;
    }


    //修改权限
    public function up($data){
      $info = [
          'node_name'=>$data['node_name'],
          'node_title'=>$data['node_title'],
          'status'=>$data['status'],
          'level'=>$data['level'],
          'pid'=>$data['pid'],
          'display'=>$data['display']
      ];
      return  DB::table('node')->where('node_id',$data['node_id'])->update($info);
    }
   
   //权限 修改状态值
   public function back($node_id){
       return DB::table('node')->where('node_id',$node_id)->update(['status'=>1]);

   }

   //获取当前等级的父级
   public function getList($level){
      return DB::table('node')->where('level',$level-1)->select('node_id','node_title')->get();
   }
}
